package com.esunny.resourcevisualization.service.impl;

import com.esunny.resourcevisualization.manage.SystemConfigManage;
import com.esunny.resourcevisualization.proxy.ZentaoSSOProxy;
import com.esunny.resourcevisualization.service.MessageService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0.0.0
 * @ClassName MessageServiceImpl
 * @Description 消息处理逻辑实现
 * @Author baochencong
 * @Date 2020/11/24 16:33
 */
@Component
public class MessageServiceImpl implements MessageService {

    @Resource
    private SystemConfigManage systemConfigManage;

    @Override
    public void sendMessageToXuanXuan(String username, String message,String url) {
        Map<String,String> paramMap = new HashMap<>(6);
        paramMap.put("username",username);
        paramMap.put("title","您有一条新的待办");
        paramMap.put("content",message);
        paramMap.put("sender_id","ResourceVisualization");
        paramMap.put("sender_name","资源可视化平台");
        paramMap.put("url",url);

        ZentaoSSOProxy.postToXuanXuan("/send", paramMap);
    }

    @Override
    public void sendAdminMessageToXuanXuan(String title, String message, String url) {
        String[] receiveMessageAdmins = systemConfigManage.getConfigByKey("receiveMessageAdmin").getValue().split(",");
        for (String receiveMessageAdmin : receiveMessageAdmins) {
            Map<String, String> paramMap = new HashMap<>(6);
            paramMap.put("username", receiveMessageAdmin);
            paramMap.put("title", title);
            paramMap.put("content", message);
            paramMap.put("sender_id", "ResourceVisualization");
            paramMap.put("sender_name", "资源可视化平台");
            paramMap.put("url", url);
            ZentaoSSOProxy.postToXuanXuan("/send", paramMap);
        }
    }



}
